//将程序变为守护进程
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
int daemonize(void) 
{
	int d = 0;
	switch(fork())
	{
		case 0:
			printf("child pid%d, %p\n", getpid(), &d);
			break;
		case -1:
			perror("fork");
			return -1;
		default:
			printf("parent pid%d, %p\n", getpid(), &d);
			exit(EXIT_SUCCESS);
	}
	return 0;
}
int main() 
{
	daemonize();
	sleep(3);
	return 0;
}
